import json
import requests
import json

from common.helper import get_request_url, get_request_headers


def update_workspace_embeddings(slug, adds=[], deletes=[]):
    response = requests.post(
        url=get_request_url(f"v1/workspace/{slug}/update-embeddings"),
        headers=get_request_headers({"Content-Type": 'application/json'}),
        data=json.dumps({
          "adds": adds,
          "deletes": deletes
        })
    )
    if response.status_code == 200:
        return json.loads(response.text)
    else:
        print(f"request failed<{response.status_code}>: {response.text}")
        raise Exception("request failed")


if __name__ == "__main__":
    result = update_workspace_embeddings(
        "test",
        ["custom-documents/obsidian.md-02e35e36-95b8-4b2d-baea-c3ba3aaaf337.json"],
        [])
    print(result)
